The present invention relates in general to the dynamic behavior of computer programs. In particular, the invention relates to stack back-tracing in computer programs to check correctness of the programs and to analyze their performance.
A computer program is structured as a set of functions or subroutines in the form of instruction sequences. Typically, during execution of a program, an initial function can call one or more functions, which, in turn, can call other functions. To understand the dynamic behavior of the program, it is necessary for a programmer to understand how a program reaches a particular program location via the set of function calls executed to reach that particular program location. This knowledge helps the programmer to identify the root cause of faults (if there are any) or to determine the full context of performance analysis statistics collected at various points during the execution of the program.
The process of determining a function call chain, step by step, is generally referred to as stack back-tracing. Typically, conventional methods for stack back-tracing require additional memory space, and they can adversely affect the performance of the program. In some cases, conventional stack back-tracing may require external metadata such as debug information produced by a compiler. It is acceptable for metadata to be present in pre-production program code. However, the metadata should not be present in production code as it becomes difficult to perform proper stack back-tracing. Other methods provide internal metadata, such as embedded back-trace tables, to enable stack back-tracing. However, this increases the size of the program-executable files and may adversely impact the performance of the program due to increased cache and memory effects. In addition, conventional methods of stack back-tracing may not be completely compatible with highly optimized code, operating system kernel code, or with programming language features such as alloca (dynamic stack allocation). In such cases, stack back-tracing may provide incorrect results or may fail to back-trace from certain points of the program.
In light of the foregoing, there is a need for a method and system for stack back-tracing which increases the efficiency of back-tracing by reducing memory usage. The method preferably should not affect the performance of the program. Further, the method preferably should be compatible with highly optimized codes, operating system kernel codes or programming language features such as alloca. Furthermore, the method preferably should work in pre-production as well as production codes.